package com.tcm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tcm.entity.User;
import com.tcm.entity.WxUser;
import com.tcm.service.UserService;
import com.tcm.service.WxUserService;
import com.tcm.mapper.WxUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author Guqier
* @description 针对表【ts_wx_user(微信登录绑定表)】的数据库操作Service实现
* @createDate 2023-08-13 16:56:09
*/
@Service
public class WxUserServiceImpl extends ServiceImpl<WxUserMapper, WxUser>
    implements WxUserService{

    @Autowired
    private UserService userService;

    /**
     * 通过微信openid获取绑定用户
     * @param openid 微信openid
     * @return 绑定用户，未绑定返回null
     */
    @Override
    public User getWxBindUserByOpenid(String openid){
        LambdaQueryWrapper<WxUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(WxUser::getOpenid, openid);
        WxUser wxUser = this.getOne(queryWrapper);
        if (wxUser == null){
            return null;
        }
        Long userId = wxUser.getUserId();
        return userService.getById(userId);
    }

}




